package com.haixiaoke.flat.lock.controller;

import com.haixiaoke.auth.AuthCheck;
import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.lock.domain.LockFace;
import com.haixiaoke.saas.lock.service.ILockFaceService;
import com.haixiaoke.saas.system.BaseController;
import com.haixiaoke.token.FrontTokenComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 锁人脸授权Controller
 * 
 * @author panda
 * @date 2025-06-26
 */
@RestController
@RequestMapping("/front/flat/lock/face")
public class FlatLockFaceController extends BaseController {
    @Autowired
    private ILockFaceService lockFaceService;
    @Autowired
    private FrontTokenComponent frontTokenComponent;

    /**
     * 查询锁人脸授权列表
     */
    @GetMapping("/page")
    public TableDataInfo list(LockFace lockFace) {
        if (lockFace.getLockId() == null) {
            return getDataTable("请选择锁");
        }
        startPage();
        List<LockFace> list = lockFaceService.selectLockFaceList(lockFace);
        return getDataTable(list);
    }

    /**
     * 新增锁人脸授权
     */
    @AuthCheck
    @PostMapping
    public AjaxResult add(@RequestBody LockFace lockFace) {
        lockFace.setCreateBy(frontTokenComponent.getLoginUser().getUser().getUserName());
        return lockFaceService.insertLockFace(lockFace);
    }

    /**
     * 更换人脸照\姓名\手机号
     */
    @AuthCheck
    @PutMapping("/editFaceImage")
    public AjaxResult editFaceImage(@RequestBody LockFace lockFace) {
        LockFace face = new LockFace();
        face.setFaceId(lockFace.getFaceId());
        face.setFaceImage(lockFace.getFaceImage());
        face.setUserName(lockFace.getUserName());
        face.setUserPhone(lockFace.getUserPhone());
        face.setUpdateBy(frontTokenComponent.getLoginUser().getUser().getUserName());
        return lockFaceService.editFaceImage(face);
    }

    /**
     * 删除锁人脸授权
     */
    @AuthCheck
	@DeleteMapping("/{faceId}")
    public AjaxResult remove(@PathVariable Long faceId) {
        return lockFaceService.deleteLockFaceByFaceId(faceId);
    }
}
